package com.dhp.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dhp.common.BaseResponse;
import com.dhp.common.ErrorCode;
import com.dhp.common.ResultUtils;
import com.dhp.exception.BusinessException;
import com.dhp.model.dto.userInterfaceInfo.UserInterfaceInfoApplyInvokeCountRequest;
import com.dhp.model.dto.userInterfaceInfo.listMyInterfaceRequest;
import com.dhp.model.vo.UserInterfaceVO;
import com.dhp.service.UserInterfaceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/userInterfaceInfo")
public class UserInterfaceInfoController {

    @Autowired
    private UserInterfaceInfoService userInterfaceInfoService;

    @PostMapping ("/apply")
    public BaseResponse<Boolean> applyInvokeCount(@RequestBody UserInterfaceInfoApplyInvokeCountRequest applyRequest, HttpServletRequest request){
        if (BeanUtil.isEmpty(applyRequest)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR , "参数为空");
        }
        return ResultUtils.success(userInterfaceInfoService.applyInvokeCount(applyRequest , request));
    }

    @PostMapping("/listMyInterface")
    public BaseResponse<Page<UserInterfaceVO>> listMyInterface(@RequestBody listMyInterfaceRequest myInterfaceRequest , HttpServletRequest request){
        Page<UserInterfaceVO> page = userInterfaceInfoService.listMyInterface(myInterfaceRequest , request);
        return ResultUtils.success(page);
    }

}
